/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.sms.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.chlitina.store.common.config.Global;
import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.web.BaseController;
import com.chlitina.store.modules.sms.entity.StoreDiagnoseDetail;
import com.chlitina.store.modules.sms.service.StoreDiagnoseDetailService;

/**
 * 店面诊断结果详细Controller
 * @author liujiang
 * @version 2013-08-01
 */
@Controller
@RequestMapping(value = Global.ADMIN_PATH+"/sms/storeDiagnoseDetail")
public class StoreDiagnoseDetailController extends BaseController {

	@Autowired
	private StoreDiagnoseDetailService storeDiagnoseDetailService;
	
	@ModelAttribute
	public StoreDiagnoseDetail get(@RequestParam(required=false) Long id) {
		if (id != null){
			return storeDiagnoseDetailService.get(id);
		}else{
			return new StoreDiagnoseDetail();
		}
	}
	
	@RequestMapping(value = {"list", ""})
	public String list(Long parentId, StoreDiagnoseDetail storeDiagnoseDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		String searchName = request.getParameter("searchName");
		Page<StoreDiagnoseDetail> page = new Page<StoreDiagnoseDetail>(request, response);
		Page<StoreDiagnoseDetail> current_page = storeDiagnoseDetailService.find(page, parentId, searchName); 
		model.addAttribute("parentId", parentId);
		model.addAttribute("searchName", searchName);
		model.addAttribute("page", current_page);
		return "modules/sms/storeDiagnoseDetailList";
	}
	
	@RequestMapping(value = "form")
	public String form(Long parentId, StoreDiagnoseDetail storeDiagnoseDetail, Model model) {
		model.addAttribute("storeDiagnoseDetail", storeDiagnoseDetail);
		return "modules/sms/storeDiagnoseDetailForm";
	}

	@RequestMapping(value = "save")
	public String save(StoreDiagnoseDetail storeDiagnoseDetail, Model model, RedirectAttributes redirectAttributes) {
		storeDiagnoseDetailService.save(storeDiagnoseDetail);
		addMessage(redirectAttributes, "保存店面诊断结果详细成功");
		return "redirect:"+Global.ADMIN_PATH+"/sms/storeDiagnoseDetail/";
	}
	
	@RequestMapping(value = "delete")
	public String delete(Long id, RedirectAttributes redirectAttributes) {
		storeDiagnoseDetailService.delete(id);
		addMessage(redirectAttributes, "删除店面诊断结果详细成功");
		return "redirect:"+Global.ADMIN_PATH+"/sms/storeDiagnoseDetail/";
	}
}
